   #include <stdio.h>
   #include <string.h>
   #define MAXLINE 1000000

//   int getline(char *line, int max);
   int getfine(char* s, int maxline);

   /* getline:  read a line into s, return length  */
   int getfine(char* s, int maxline)
   {
       int c, i;
       for (i=0; ((c=getchar())!=EOF) && c!='\n'; i++)
       {
           *s = c;
           s++;
       }
       if (c == '\n')
       {
           *s = 0;
           ++i;
       }
       //printf("%d : len \n",i);
       return i;

   }



   /* find:  print lines that match pattern from 1st arg */
int   main(int argc, char *argv[])
   {
       char line[MAXLINE];
       int found = 0;

       if (argc != 2)
           printf("Usage: find pattern\n");
       else
           while (getfine(line, MAXLINE) > 0)
               if (strstr(line, argv[1]) != NULL) {
                   printf("%s \n", line);
                   found++;
                   // printf("found:%d\n",found);
                                 }
       return found;
   }
